﻿<!doctype html>
<html>
<head>
    <title>SpreadJS - Basic Formula TextBox</title>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

    <link href="../../../external/spreadjs/css/gcspread.sheets.excel2013white.9.40.20161.0.css" rel="stylesheet" type="text/css" />

    <script src="../../../external/external/jquery-1.8.2.min.js" type="text/javascript"></script>

    <script type="text/javascript" src="../../../external/spreadjs/gcspread.sheets.all.9.40.20161.0.min.js"></script>

    <script id="scriptInit" type="text/javascript">
    /*code_begin*/
    $(document).ready(function () {
        var spread = new GcSpread.Sheets.Spread(document.getElementById("ss"), { sheetCount: 2 });
        initSpread(spread);
    });

    function initSpread(spread) {
        var spreadNS = GcSpread.Sheets;
        var fbx = new spreadNS.FormulaTextBox(document.getElementById('formulaBar'));
        fbx.spread(spread);

        spread.isPaintSuspended(true);

        var sheet2 = spread.sheets[1];
        sheet2.setArray(0, 0, [[1, 4, 7], [2, 5, 8], [3, 6, 9]]);

        var sheet = spread.sheets[0];
        sheet.allowCellOverflow(true);

        sheet.setValue(1, 2, "When typing any Formula in cell or area above sheet, text box will display for helping you.");
        sheet.setValue(2, 2, "For example: =sum(1,2,3)");

        for (var i = 5; i < 35; i++) {
            for (var j = 1; j < 15; j++) {
                sheet.setValue(i, j, i * j);
            }
        }

        // used to help show table support feature
        sheet.addTable("Table1", 4, 7, 5, 4);
        for (var c = 7; c <= 10; c++) {
            sheet.setColumnWidth(c, 90);
        }
        sheet.setFormula(3, 0, "Table1[[#Headers],[Column2]]");

        // used to help show custome name support feature
        sheet.addCustomName("RangeB6C9", "$B$6:$C$9", 0, 0);
        sheet.addCustomName("Range2", "SUM($C$11:$D$14)", 0, 0);

        sheet.setFormula(4, 0, "AVERAGE(RangeB6C9)");

        // used to help show multi supported reference types
        var formula = "SUM(B6:C9,E6:F9,Table1[#Data],Range2,F11:J14,D16:I17)";
        sheet.getCell(1, 0).formula(formula);
        sheet.setActiveCell(1, 0);
        fbx.text("=" + formula);

        // used to help show cross sheet reference
        sheet.setFormula(5, 0, "SUM(sheet2!A1:C3)");

        sheet.getCells(1, 0, 5, 0).foreColor("green");

        spread.isPaintSuspended(false);
    };
    /*code_end*/
    </script>

</head>
<body>
<div class="sample-turtorial">
    <div class="demo-options">
        <div class="option-row">
            <div id="formulaBar" contenteditable="true" spellcheck="false" style="border: 1px solid #808080;width:100%;"></div>
        </div>
    </div>
    <div id="ss" style="width:100%; height:400px;border: 1px solid gray;"></div>
</div>
</body>
</html>
